<template>
	<view class="boxs">
		<view class="top">
			<u-navbar :is-back="true" title="评论区" :border-bottom="false"></u-navbar>
		</view>
		<view class="showList " :style="styleTwo" v-if="list.length>0">
			<view class="item" v-for="item in list " :key="item.comment_id">
				<view class="top flc">
					<view class="avatar">
						<u-avatar :src="item.img" size="64" mode="circle"></u-avatar>
					</view>
					<view class="name_time">
						<view class="name">
							{{item.nickname}}
						</view>
						<view class="time">
							{{item.create_time}}
						</view>
					</view>
				</view>
				<view class="bottom">
					{{item.content}}
				</view>

			</view>
		</view>
		<view class="noData" v-else style="width: 410rpx;height: 240rpx; margin: 60rpx auto;">
			<image src="../../static/img/empty.png" mode="widthFix" style="width: 410rpx;"></image>
		</view>
		<view class="btns flc" :style="styleOne">
			<view class="input left">
				<textarea v-model="content" style="width: 460rpx;"></textarea>
			</view>
			<view class="right flc">
				<view class="type">
					<u-icon :name="'/static/icon/enjoy.png'" v-if="open" @click="openEnjoy" size="60"></u-icon>
					<u-icon :name="'/static/icon/keydown.png'" v-else @click="closeEnjoy" size="60"></u-icon>
				</view>
				<view class="send" @click="sendMessage">
					发送
				</view>
			</view>
		</view>
		<view class="enjoy"  >
			<view class="swiperBox" >
				<view class="uni-margin-wrap">
					<swiper class="swiper" circular :indicator-dots="true" :autoplay="false" :style="styleOne" >
						<swiper-item v-for="(item, key) in emojiData" :key="key" class="slider-emoji">
							<view class="icon" v-for="(emoji, index) in item" :key="index" @click="selemoji(emoji)">
								{{emoji}}
							</view>
						</swiper-item>
					</swiper>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import emoji from "/js_sdk/m-emoji/m-emoji_2.0.0/emoji.js";
	// import {
	// 	getComment,
	// } from '@/api/product.js'
	// import {getUserInfo,send} from '@/api/user.js'
	import baseUrl from '@/config/config.js'
import { toast } from "../../utils/common";
	export default {
		data() {
			return {
				list: [],
				emojiData:[],
				open:true,
				styleOne:{},
				styleTwo:{},
				content:"",
				userInfo:"",
				id:""

			};
		},
		onLoad(res) {
			this.init(res.id)
			this.id =res.id
			var page = Math.ceil(emoji.length/21);
			    for (let i = 0; i < page; i++) {
			    this.emojiData[i] = [];
			    for (let k = 0; k < 21; k++) {
			        emoji[i*21+k]?this.emojiData[i].push(
			        emoji[i*21+k]
			        ):''
			    }
				
			} 
			let newArr = []
			this.emojiData = this.emojiData.slice(0, 12)
			console.log(this.emojiData);
			for (var i = 0; i < this.emojiData.length; i+=2) {
				let arr =[]
				this.emojiData[i].forEach(item=>{
					arr.push(item)
				})
				this.emojiData[i+1].forEach(item=>{
					arr.push(item)
				})
				newArr.push(arr)
				
			}
			this.emojiData = newArr
		},
		methods: {
			init(id) {
				getComment(id).then(res => {
					this.list = res.result.list.map(item => {
						return {
							...item,
							img: baseUrl.baseUrl + item.avatar
						}
					})
				})
				getUserInfo().then(res=>{
					console.log("我的信息",res);
					this.userInfo = res.result.obj
				})
			},
			openEnjoy(){
				this.open = false
				this.styleOne = {
					transform: 'translateY(-500rpx)'
				}
				this.styleTwo={
					maxHeight: '750rpx'
				}
			},
			closeEnjoy(){
				this.open = true
				this.styleOne = {
					transform: 'translateY(0rpx)'
				}
				this.styleTwo = {
					maxHeight: '1250rpx'
				}
			},
			selemoji(item){
				console.log(item);
				this.content = this.content+item
			},
			sendMessage(){
				if(!this.content){
					toast("请勿发送空信息")
					return
				}
				var {nickname,user_id,avatar} = this.userInfo
				let obj ={
					avatar,
					content: this.content,
					nickname,
					source_field: "points_mall_id",
					source_id: this.id,
					source_table: "points_mall",
					user_id
				}
				send(obj).then(res=>{
					console.log(res);
					if(res.result==1){
						toast("发送成功")
						this.content =""
						this.init(this.id)
					}
				})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	.boxs{
		width: 750rpx;
		box-sizing: border-box;
		padding: 1rpx 0;
		overflow: hidden;
		height: 100vh;
		background-color: #f5f5f5;
		position: fixed;
		top: 0;
		left: 0;
	}
	.showList {
		width: 710rpx;
		box-sizing: border-box;
		margin: 20rpx;
		overflow: auto;
		max-height: 1250rpx;
		background-color: #fff;
		padding: 20rpx;
		border-radius: 20rpx;

		&::-webkit-scrollbar {
			display: none;
		}

		.item {
			padding:20rpx 0 ;
			border-top: 1rpx solid #dedede;

			.name_time {
				height: 64rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				margin-left: 20rpx;
			}

			.name_time .name {
				font-size: 26rpx;
				color: #333;
			}

			.name_time .time {
				font-size: 22rpx;
				color: #666;
			}
			
		}
		.item:nth-child(1){
			border: none;
		}

		.bottom {
			width: 550rpx;
			margin: 20rpx auto;
			
		}
	}
	.swiper{
		width: 750rpx;
		height: 600rpx;
		position: fixed;
		bottom: 0;
		.slider-emoji{
			display: flex;
			flex-wrap: wrap;
			.icon{
				font-size: 50rpx;
			}
		}
	}
	.btns{
		position: absolute;
		bottom: 0;
		left: 0;
		transition: all linear 0.3s; 
		min-height: 120rpx;
		background-color: #ffffff;
		width: 750rpx;
		padding: 10rpx 40rpx;
		transition: all linear 0.3s;
		.input{
			background-color: #f5f5f5;
			width: 500rpx;
			padding: 10rpx 20rpx;
			font-size: 32rpx;
			height: 60rpx;
		}
		.right{
			width: 210rpx;
		}
		.right .type{
			width: 60rpx;
			height: 60rpx;
			margin-left: 20rpx;
		}
		.right .send{
			height: 60rpx;
			width: 100rpx;
			text-align: center;
			line-height: 60rpx;
			font-size: 24rpx;
			margin-left: 20rpx;
			background-color: #f5ce31;
			color: #fff;
			
		}
	}
	
	.swiper{
		transition: all linear 0.3s; 
		position: absolute;
		bottom: -500rpx;
		background-color: #fff;
		left: 0;
		height: 500rpx;
		box-sizing: border-box;
		
	}
</style>